package alo.p10.work;

import alo.p10.HeapSort;

/**
 * @ClassName CheckDuplicatesArray
 * @Description 检查数组是否存在重复元素
 * @Author Fanxc
 * @DATE 2021/3/12 14:26
 * @Version 1.0
 */
public class CheckDuplicatesArray {
    //双重循环
    boolean checkDuplicatesArray(int[] A,int n){
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if (A[i]==A[j]){
                    return true;
                }
            }
        }
        return false;
    }
    //先排序，再查找
    boolean checkDuplicatesArray2(int[] A,int n){
        HeapSort heapSort=new HeapSort();
        heapSort.heapSort(A,0,n-1);
        for (int i = 0; i < n - 1; i++) {
            if (A[i]==A[i+1]){
                return true;
            }
        }
        return false;
    }
}
